WebWork 2 : Using Checkboxes
This page last changed on Nov 30, 2004 by jcarreira.
Using Checkboxes (General)The biggest gotcha for newbies is that you must set the 'value' attribute in the html <input> field to use Checkboxes with WW. By default your browser will set this to some value. Firebird uses "on" - not sure what IE or others use. You must make this a sensible value for whatever property you are setting.Using Checkboxes to set boolean fieldsHTML:<input type="checkbox" name="user.lockedOut" value="true"/> private boolean m_lockedOut = false; public void setLockedOut(boolean lockedOut) { m_lockedOut = lockedOut; } Using Checkboxes to set a collectionOur user has a number of priviliges that are stored as a Set of strings. To use checkboxes for these, we have HTML that looks like:<input type="checkbox" name="user.priv" value="boss"/> <input type="checkbox" name="user.priv" value="admin"/> <input type="checkbox" name="user.priv" value="manager"/> Say a user checks the first 2; the browser will send the query string: user.priv=boss&user.priv=admin. OGNL will end up callingaction.getUser().setPriv(String[] {"boss", "admin"}) You can write this method like: Set m_privileges = new HashSet(); public void setPriv(String[] privs) { for (int i = 0; i < privs.length; i++) { m_privileges.add(privs[i]); } } Full Detailed example:This example uses a kind-of XW:Interceptors#ModelDriven Action. The action returns a single getter for the User object whose values are populated. |
Document generated by Confluence on Dec 14, 2004 16:36 |